#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 2e5+10;

int n,k,h[N],cnt;
ll ans;
struct edge{int v,nxt;}e[N<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

struct stu{
	ll f[6],g[6];
	stu(){memset(f,0,sizeof f);memset(g,0,sizeof g);}
	stu operator << (int x){
		stu c; if(k == 1){c.f[0] = f[0] + g[0]; c.g[0] = g[0];return c;}
		for(int i = k - 1;i >= 1;i--) c.f[i] = f[i - 1],c.g[i] = g[i-1];
		c.f[0] = f[k - 1],c.g[0] = g[k - 1]; c.f[1] += g[0];
		return c;
	}
	friend stu operator + (stu a,stu b){
		stu c; for(int i = 0;i < k;i++) c.f[i] = a.f[i] + b.f[i],c.g[i] = a.g[i] + b.g[i];
		return c;
	}
	friend stu operator - (stu a,stu b){
		stu c; for(int i = 0;i < k;i++) c.f[i] = a.f[i] - b.f[i],c.g[i] = a.g[i] - b.g[i];
		return c;
	}
	ll cal(){ll res = 0;for(int i = 0;i < k;i++) res += f[i];return res;}
}f[N];

void dfs(int x,int p){
	f[x].g[0] = 1;
	for(int i = h[x],y;i;i = e[i].nxt)
		if((y = e[i].v) ^ p){
			dfs(y,x); f[x] = f[x] + (f[y] << 1);
		}
}

void dp(int x,int p){
	for(int i = h[x],y;i;i = e[i].nxt)
		if((y = e[i].v) ^ p){
			f[y] = ((f[x] - (f[y] << 1)) << 1) + f[y]; dp(y,x); 
		}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in;
	for(int i = 1,u,v;i < n;i++) u = in,v = in,link(u,v),link(v,u);
	dfs(1,0); dp(1,0);
	for(int i = 1;i <= n;i++) ans += f[i].cal();
	printf("%lld\n",ans >> 1);
	return 0;
}
